home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 2 / CU Amiga Magazine's Super CD-ROM 02 (1996)(EMAP Images)(GB)[!][issue 1996-04].iso / 17_bit_pd / 17bitgif / utility / amiga / gd_v1_11.lha / gd1.1.1 / gddemo.c < prev    next >
C/C++ Source or Header  |  1994-12-03  |  3KB  |  113 lines

  1. #include <stdio.h>
  2. #include "gd.h"
  3. #include "gdfontl.h"
  4. #include "gdfonts.h"
  5.  
  6. int main() 
  7. {
  8.     /* Input and output files */
  9.     FILE *in;
  10.     FILE *out;
  11.  
  12.     /* Input and output images */
  13.     gdImagePtr im_in, im_out;
  14.  
  15.     /* Brush image */
  16.     gdImagePtr brush;
  17.  
  18.     /* Color indexes */
  19.     int white;
  20.     int blue;
  21.     int red;
  22.     int green;
  23.  
  24.     /* Points for polygon */
  25.     gdPoint points[3];
  26.  
  27.     /* Create output image, 128 by 128 pixels. */
  28.     im_out = gdImageCreate(128, 128);
  29.  
  30.     /* First color allocated is background. */
  31.     white = gdImageColorAllocate(im_out, 255, 255, 255);
  32.  
  33.     /* Set transparent color. */
  34.     gdImageColorTransparent(im_out, white);
  35.  
  36.     /* Try to load demoin.gif and paste part of it into the
  37.         output image. */
  38.  
  39.     in = fopen("demoin.gif", "rb");
  40.     if (!in) {
  41.         fprintf(stderr, "Can't load source image; this demo\n");
  42.         fprintf(stderr, "is much more impressive if demoin.gif\n");
  43.         fprintf(stderr, "is available.\n");
  44.         im_in = 0;
  45.     } else {
  46.         im_in = gdImageCreateFromGif(in);
  47.         fclose(in);
  48.         /* Now copy, and magnify as we do so */
  49.         gdImageCopyResized(im_out, im_in, 
  50.             16, 16, 0, 0, 96, 96, 128, 128);        
  51.     }
  52.     red = gdImageColorAllocate(im_out, 255, 0, 0);
  53.     green = gdImageColorAllocate(im_out, 0, 255, 0);
  54.     blue = gdImageColorAllocate(im_out, 0, 0, 255);
  55.     /* Rectangle */
  56.     gdImageLine(im_out, 8, 8, 120, 8, green);    
  57.     gdImageLine(im_out, 120, 8, 120, 120, green);    
  58.     gdImageLine(im_out, 120, 120, 8, 120, green);    
  59.     gdImageLine(im_out, 8, 120, 8, 8, green);    
  60.     /* Text */
  61.     gdImageString(im_out, gdFontLarge, 16, 16, "hi", red);
  62.     gdImageStringUp(im_out, gdFontSmall, 32, 32, "hi", red);
  63.     /* Circle */
  64.     gdImageArc(im_out, 64, 64, 30, 10, 0, 360, blue);
  65.     /* Arc */
  66.     gdImageArc(im_out, 64, 64, 20, 20, 45, 135, blue);
  67.     /* Flood fill */
  68.     gdImageFill(im_out, 4, 4, blue);
  69.     /* Polygon */
  70.     points[0].x = 32;
  71.     points[0].y = 0;
  72.     points[1].x = 0;
  73.     points[1].y = 64;    
  74.     points[2].x = 64;
  75.     points[2].y = 64;    
  76.     gdImageFilledPolygon(im_out, points, 3, green);
  77.     /* Brush. A fairly wild example also involving a line style! */
  78.     if (im_in) {
  79.         int style[8];
  80.         brush = gdImageCreate(8, 8);
  81.         gdImageCopyResized(brush, im_in,
  82.             0, 0, 0, 0, 
  83.             gdImageSX(brush), gdImageSY(brush),
  84.             gdImageSX(im_in), gdImageSY(im_in));
  85.         gdImageSetBrush(im_out, brush);    
  86.         /* With a style, so they won't overprint each other */
  87.         style[0] = 0;
  88.         style[1] = 0;
  89.         style[2] = 0;
  90.         style[3] = 0;
  91.         style[4] = 0;
  92.         style[5] = 0;
  93.         style[6] = 0;
  94.         style[7] = 1;
  95.         gdImageSetStyle(im_out, style, 8);
  96.         /* Draw the styled, brushed line */
  97.         gdImageLine(im_out, 0, 0, 128, 128, gdStyledBrushed);
  98.     }
  99.     /* Make output image interlaced (allows "fade in" in some viewers,
  100.         and in the latest web browsers) */
  101.     gdImageInterlace(im_out, 1);
  102.     out = fopen("demoout.gif", "wb");
  103.     /* Write GIF */
  104.     gdImageGif(im_out, out);
  105.     fclose(out);
  106.     gdImageDestroy(im_out);
  107.     if (im_in) {
  108.         gdImageDestroy(im_in);
  109.     }
  110.     return 0;
  111. }
  112.  
  113.